package com.fms.handler;

import com.fms.result.ResultData;
import com.fms.exception.NotLoginException;
import com.fms.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
//异常处理
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    public ResultData serviceException(ServiceException e){
        log.info(e.getMessage());
        return ResultData.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ResultData exception(Exception e){
        e.printStackTrace();
        return ResultData.error("System exception, Please Wait...");
    }

    @ExceptionHandler(NotLoginException.class)
    public ResultData notLoginException(NotLoginException e){
        log.info(e.getMessage());
        return ResultData.error(e.getMessage()).setCode(e.getCode());
    }
}
